package com.ita.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.ita.dao.WareHouseDao;
import com.ita.pojo.WareHouse;
import com.ita.util.DBUtil;

public class WareHouseDaoImpl implements WareHouseDao{

	@Override
	public List<WareHouse> findAll() {
		
		List<WareHouse> list = new ArrayList<WareHouse>();
		String sql = "select * from warehouse";
		Connection con = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			con = DBUtil.createByJNDI();
			pst = con.prepareStatement(sql);
			rs = pst.executeQuery();
			while (rs.next()) {
				WareHouse w = new WareHouse();
				w.setId(rs.getInt("id"));
				w.setAddr(rs.getString("addr"));
				list.add(w);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(con, pst, rs);
		}
		return list;
	}

}
